package com.lei.day03rikao;

import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;

import java.util.Timer;
import java.util.TimerTask;

@Route(path = "/day03rikao/ZMainActivity")
public class ZMainActivity extends AppCompatActivity {
    @Autowired(name = "name")
    String name;
    private TextView tv1;
    private TextView tv2;
    private int index = 5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zmain);
        ARouter.getInstance().inject(this);
        initView();
        Animation animation = AnimationUtils.loadAnimation(ZMainActivity.this, R.anim.cccc);
        tv1.setAnimation(animation);

    }

    private void initView() {
        tv1 = (TextView) findViewById(R.id.tv1_name);
        tv2 = (TextView) findViewById(R.id.tv2);
        tv1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tv1.setText(name);

            }
        });
        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (index<0){
                            timer.cancel();
                        }else {
                            tv2.setText("倒计时"+(index--)+"秒");
                        }
                    }
                });
            }
        },0,1000);
    }
}
